{extend name="tpl/site_0/default/pc/public/layout.html" /}
{block name='title'}领券中心{$webConfig.WEBNAME}{/block}
{block name='head'}
<style>
    .active{
        background: red;
    }
</style>
{/block}
{block name='body'}
{include file="tpl/site_0/default/pc/public/head.html" /}

<div style="height: 43px;"></div>
<div class="ord-pro">
    <div class="weui-flex box">
        <div class="img">
            <img src="{$cardInfo.card_image}" alt="">
        </div>
        <div class="weui-flex__item">
            <h2>{$cardInfo.title}</h2>
            <div class="guige">{$cardInfo.sub_title}</div>
            <div class="weui-flex">
                <div class="weui-flex__item">{$cardInfo.sale_money}</div>
            </div>
        </div>
    </div>
</div>
<div class="other">
    <form method="post" id="payForm">
        <input type="hidden" name="openid" value="{$Request.param.openid}" />
        <input type="hidden" name="device" id="device" value="{$device}" />
        <input type="hidden" name="site_id" value="0" />
        <input type="hidden" name="order_type" id="orderType" value="card" />
        <input type="hidden" name="order_sn" value="{$orderInfo.order_sn}" />
        <input type="hidden" name="pay_code" value=""/>
        <div class="order-row" style="padding:10px 0;">
            <h2>支付信息</h2>
            <div class="pay-type">
                <div class="pay-type">
                    <a href="javascript:;" onclick="setPay(this)" data-code="alipay" class="active">
                        <i class="iconfont icon-alipay"></i>                    支付宝</a>
                    <a href="javascript:;" onclick="setPay(this)" data-code="wxpay" class="">
                        <i class="iconfont icon-weixinzhifu"></i>                    微信支付</a>
                </div>
            </div>
        </div>
        <div class="order-row" style="padding:30px;text-align:center;">
            <a href="javascript:;" class="pay-btn" onclick="doPay(this);">立即支付</a>
            <a href="{:url('home/Order/index')}" class="order-btn">订单中心</a>
        </div>
    </form>

</div>

<!--底部-->
{/block}
{block name="script"}
<script src="/public/plugins/layerMobile/layer.js"></script>
<script>
    function setPay(obj) {
        var payCode=$(obj).data('code');
        $("input[name='pay_code']").val(payCode);
        $(obj).addClass('active').siblings().removeClass('active');
    }
    var device = $('#device').val();
    function doPay(obj) {
        var orderPrice = "{$orderInfo.order_price}";
        var payCode = $("input[name='pay_code']").val();
        //支付宝支付
        if(payCode=='alipay'){
            $('#payForm').attr('action',"{:url('plus/Alipay/pay')}");
            $('#payForm').submit();
            return false;
        }
        //微信支付
        if(payCode=='wxpay'){
            {eq name="device" value="3"}
            callpay();
            {else/}
            $.post("{:url('plus/Wxpay/pay')}",$('#payForm').serialize(),function(res){
                if(res.code==1){
                    var url="{:url('plus/Help/qrcode')}?qtext="+res.data;
                    var html = '<img style="width: 100%;height: auto" src="'+url+'" />';
                    //信息框
                    layer.open({
                        style: 'width: 90vw',
                        content: html
                    });
                }else{
                    alert(res.msg);
                }
            });
            {/eq}
        }
    }
    {eq name="device" value="3"}
    //调用微信JS api 支付
    function jsApiCall() {
        WeixinJSBridge.invoke('getBrandWCPayRequest',{$jsApiParameters}, function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    location.href = "{:url('home/Order/index')}";
                    return false;
                } else {
                    if (res.err_msg == "get_brand_wcpay_request:cancel") {
                        location.href = "{:url('home/Order/index')}";
                    } else {
                        alert('错误代码：' + res.err_code + '<br/>错误描述：' + res.err_desc + '<br/>错误：' + res.err_msg);
                    }
                }
            }
        );
    }
    //微信支付
    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }
    {/eq}
</script>
{/block}